package com.baizhi.controller;

import com.baizhi.entity.AdminLog;
import com.baizhi.service.AdminLogService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("log")
public class AdminLogController {

    @Autowired
    private AdminLogService adminLogService;

    //展示
    @ResponseBody
    @RequestMapping("show")
    public Map showAll(int page,int limit){
        Map map = new HashMap();
        PageInfo<AdminLog> pageInfo = adminLogService.show(page, limit);
        map.put("code",0);
        map.put("msg","");
        map.put("count",pageInfo.getTotal());
        map.put("data",pageInfo.getList());
        return map;
    }

    //删除
    @ResponseBody
    @RequestMapping("delete")
    public Map delete(int id){
        Map map = new HashMap();
        try {
            adminLogService.remove(id);
            map.put("isDelete",true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isDelete",false);
        }
        return map;
    }

    //批量删除
    @ResponseBody
    @RequestMapping("deleteMany")
    public Map deleteMany(int[] ids){
        Map map = new HashMap();
        try {
            adminLogService.deleteMany(ids);
            map.put("isDeleteMany",true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isDeleteMany",false);
        }
        return map;
    }

}
